package com.listerner;

import com.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Service;

@Service
public class RedisMessageListener implements MessageListener {

    @Autowired
    private RoomService roomService;

    @Override
    public void onMessage(Message message, byte[] bytes) {
        String expireKey = new String(message.getBody());
        String[] arry = expireKey.split("_");
        if (arry!=null && arry.length>1)
        {
            String key = arry[0];
            String value = arry[1];
            switch (key)
            {

                case "heart":
                    String mac = value;
                    roomService.offLine(mac);
                    //发送离线的指令
                    roomService.sendOnline(mac,0);
                    break;
            }
        }


    }
}